package com.richie696.connect.http11;

import com.richie696.catalina.Header;
import com.richie696.connect.ProtocolHandler;


public abstract class AbstractHttp11Protocol implements ProtocolHandler {

    protected Header getHeader(String content) {
        Header header = new Header();
        String[] rows = content.split("\\r\\n");
        for (String row : rows) {
            if (!row.contains(":")) {
                String[] values = row.split(" ");
                header.setMethod(RequestMethod.valueOf(values[0]));
                header.setUrl(values[1]);
                header.setProtocol(values[2]);
            } else {
                String[] values = row.split(": ");
                header.addHeader(values[0].trim(), values[1].trim());
            }
        }
        return header;
    }

}
